const fs = require('fs')
const path = require('path')
const readline = require('readline')

const fileName = path.join(__dirname, '../', '../', 'logs', 'access.log')

// 创建 readStream
const readStream = fs.createReadStream(fileName)

// 创建readline 对象
const rl = readline.createInterface({
  input: readStream
})

let edgeNum = 0
let sum = 0

// 逐行读取
rl.on('line', lineData => {
  if (!lineData) return

  sum++

  const arr = lineData.split(' -- ')
  if (arr[2] && arr[2].indexOf('Edge') > 0) {
    edgeNum++
  }
})

rl.on('close', () => {
  console.log('Edge 占比：', edgeNum / sum)
})
